package com.ezhuan.common.demo;

import com.ezhuan.outer.controller.CommonOuterController;
import com.ezhuan.outer.controller.NotifyOuterController;
import com.ezhuan.outer.controller.SystemOuterController;
import com.ezhuan.outer.controller.TaskOuterController;
import com.ezhuan.outer.controller.UsersOuterController;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.cron4j.Cron4jPlugin;
import com.jfinal.template.Engine;

/**
 * Jfinal的配置项
 * 
 * @author wangshSxt
 *
 */
public class DemoConfig extends JFinalConfig
{
	private String configName = "system.properties" ; 

	@Override
	public void configConstant(Constants constants)
	{
		/* 加载配置文件 */
		PropKit.use(configName,"UTF-8");
		/* 开启开发者模式 */
		constants.setDevMode(PropKit.getBoolean("devMode"));
	}

	@Override
	public void configEngine(Engine engine)
	{
	}

	@Override
	public void configHandler(Handlers handlers)
	{
	}

	@Override
	public void configInterceptor(Interceptors interceptors)
	{
	}

	@Override
	public void configPlugin(Plugins plugins)
	{
		/* 配置C3p0 */
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.use(configName).getProperties());
		plugins.add(c3p0Plugin);
		
		/* 配置POJO模块 */
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		plugins.add(arp);
		
		/* 加载定时任务 */
		Cron4jPlugin cron4jPlugin = new Cron4jPlugin(PropKit.use(configName));
		plugins.add(cron4jPlugin);
	}

	@Override
	public void configRoute(Routes routes)
	{
		/* /outer/head/表示登陆后才可以访问 */
		routes.add("/outer/head/users", UsersOuterController.class);
		routes.add("/outer/head/system", SystemOuterController.class);
		routes.add("/outer/head/task", TaskOuterController.class);
		/* 不需要登陆就可以访问 */
		routes.add("/outer/common", CommonOuterController.class);
		routes.add("/outer/notify", NotifyOuterController.class);
	}
}
